with Ada.Text_IO; use Ada.Text_IO;
with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;

procedure Echiquier is
   -- chestboard
   type Board is array(1..8,1..8) of Integer;
   Chestboard : Board;
   ChestBoard2 : Board;
   X : Integer ;
   Y : Integer ;

   -- initialisation ------------------------------------------------
   procedure Init(Chestboard : in out Board) is
      -- decl
      -- instruc
   begin
      for L in Chestboard'Range loop
         for C in Chestboard'Range loop
            Chestboard(L,C) := 0;
         end loop ;
      end loop ;
   end Init;

   -- display --------------------------------------------------------
   procedure Display (Chestboard : Board) is
      -- decl

      -- instruc
   begin
      for L in Chestboard'Range loop
         for C in Chestboard'Range loop

            Put(Integer'Image(Chestboard(L,C)));
         end loop;

         New_Line;
      end loop;
   end Display;

   -- bishop (fou en ENG)  --
   procedure Bishop(X : Integer ; Y : Integer; Chestboard: in out  Board) is
      -- decl
      X0 : Integer ;
      X1 : Integer ;
      Y0 : Integer ;
      Y1 : Integer ;
      -- instruc
   begin
      -- position de départ
      -- dec
      X0 := X + Integer'Min(X ,  Y );
      Y0 := Y - Integer'Min(Y ,  X );
      -- asc
      X1 := X - Integer'Min(X , 8 - Y );
      Y1 := Y - Integer'Min(X  , 8 - Y  );
      -- ascendant
      for I in Chestboard'Range  loop
         if X1+I in 1..8 and Y1 +I in 1..8 then
            Chestboard(X1 + I , Y1 +I) := 1;
         end if;
      end loop;

      -- descendant
      for I in Chestboard'Range  loop
         if X0-I in 1..8 and Y0 +I in 1..8 then
            Chestboard(X0 - I , Y0 +I) := 1;
         end if;
      end loop;
      Put_Line("----Bishop----");

      Display(Chestboard);
   end Bishop;

   -- Tower ---------------
   procedure Tower (X: Integer ; Y : Integer ;  Chestboard : in out Board ) is
      --

   begin
      for I in Chestboard'Range loop
         Chestboard(I,Y) := 1;
      end loop;

      for I in Chestboard'Range loop
         Chestboard(X,I) := 1;
      end loop;
      Put_Line("--Tower--");
      Display(Chestboard);
   end Tower;


   ----- principale
begin
   -- init
   Init(Chestboard);
   Init(Chestboard2);
   -- questions
   Put_Line("X ?");
   Put(">");
   Get(X);
   Put_Line("Y ?");
   Put(">");
   Get(Y);
   -- bishop
   Bishop(X,Y,Chestboard);
   -- tower
   Tower(X,Y,Chestboard2);

end Echiquier;


